import java.util.*;
import java.lang.*;

public class MinMaxNode<T> {
	
	public T state;
	public int utilValue;
	public List<MinMaxNode<T>> children = new ArrayList(0);
	public int[] move;
	public int dimensions;
	public int turn;

//    public MinMaxNode() 
//    {
//    }
    public MinMaxNode(T _state, List _move, int _dimensions, int _turn)
    {
    	if (_move.size() == 2)
    	{
    		move = new int[2];
    		move[0] = ((Integer)(_move.get(0))).intValue();
    		move[1] = ((Integer)(_move.get(1))).intValue();
    	} else if (_move.size() == 3)
    	{
    		move = new int[3];
    		move[0] = ((Integer)(_move.get(0))).intValue();
    		move[1] = ((Integer)(_move.get(1))).intValue();
    		move[2] = ((Integer)(_move.get(2))).intValue();
    	} else
    	{
    		//error
    	}
    	state = _state;
    	dimensions = _dimensions;
    	turn = _turn;
    }
//    public boolean equals(T _state)
  //  {
   // 	return true;
   // }
    public void addChild(MinMaxNode aChild)
    {
    	children.add(aChild);
    }
    public List<MinMaxNode<T>> getChildren()
    {
    	return children;
    }
    public void setUtilValue(int _utilValue)
    {
    	utilValue = _utilValue;
    }
    public int getUtilValue()
    {
    	return utilValue;
    }
    public int getChildrenSize()
    {
    	return children.size();
    }
    public T getState()
    {
    	return state;
    }
    public int[] getMove()
    {
    	return move;
    }
    public int getTurn()
    {
    	return turn;
    }
    public boolean boardEquals(T _state, int boardSize)
    {
    	if (dimensions == 2)
    	{
    		int[][] state1 = (int[][])state;
    		int[][] state2 = (int[][])_state;
    		for (int i = 0; i < boardSize; i++)
    		{
    			for (int j = 0; j < boardSize; j++)
    			{
    				if (state1[i][j] != state2[i][j])
    					return false;
    			}
    		}
    		return true;
    	}
    	else
    	{
    		
    	}
    	return false;
    }
    public int getDepth(T _state, int depth)
    {
    	System.out.print("getDepth\n");
    	if (state.equals(_state))
    	{
    		System.out.print("found it\n");
    		return depth;
    	}
    	else if (children.size() == 0)
    	{
    		return 0;
    	}
    	else
    	{
    		System.out.print("calling children");
    		int i;
    		int aDepth = depth;
    		for (i = 0; i < children.size(); i++)
    		{
    			int result = children.get(i).getDepth(_state, depth+1);
    			if (result > aDepth)
    			{
    				aDepth = result;
    			}
    		}
    		return aDepth;
    	}
    }
}